package bairui.international.model.status;

/**
 *
 * (用户状态)State_User
 */
@com.lianjing.sh.processing.info.annotation.GenerateInfoModel
@com.lianjing.sh.model.common.annotation.Comment("用户状态")
@com.lianjing.sh.processing.info.annotation.InfoComment("用户状态")
public enum State_User implements com.sh_lianjing.state.Statable, com.sh_lianjing.standard.EnumCommentable<State_User> {

	/**
	 * <b>状态:</b> </br>
	 * (已冻结)Freezed</br>
	 */
	@com.lianjing.sh.model.common.annotation.Comment("已冻结")
	@com.lianjing.sh.processing.info.annotation.InfoComment("已冻结")
	Freezed("已冻结")
,
	/**
	 * <b>状态:</b> </br>
	 * (正常)Normaled</br>
	 */
	@com.lianjing.sh.model.common.annotation.Comment("正常")
	@com.lianjing.sh.processing.info.annotation.InfoComment("正常")
	Normaled("正常")
;

	private static java.util.Map<String, State_User> Cache = new java.util.HashMap<>();
	static{
		for(State_User enumItem : State_User.values()){
			Cache.put(enumItem.getComment(), enumItem);
		}
	}

	private String comment;

	private State_User(String comment){
		this.comment = comment;
	}

	@Override
	public String toString() {
		return comment;
	}

	@Override
	public String getComment() {
		return comment;
	}

	/**
	 * 通过备注解析状态相关
	 */
	@Override
	public State_User parseByComment(String comment) {
		return State_User.parse(comment);
	}

	public static State_User parse(String comment) {
		State_User enumItem = Cache.get(comment);
		if(null == enumItem){
			 throw new com.sh_lianjing.standard.exception.EnumCommentableException(State_User.class, comment);
		}
		return enumItem;
	}

	/**
	 * from 转换方法相关
	 */
	/** <b>冻结(正常状态)</b> */
	public com.sh_lianjing.state.StateTransition<State_User> t_freeze_from_Normaled() throws com.sh_lianjing.state.StateConvertException {
		if(this != Normaled){
			throw new com.sh_lianjing.state.StateConvertException(this, Freezed);
		}
		return new com.sh_lianjing.state.StateTransition<State_User>("冻结", this, Freezed);
	}

	/** <b>恢复(已冻结状态)</b> */
	public com.sh_lianjing.state.StateTransition<State_User> t_unfreeze_from_Freezed() throws com.sh_lianjing.state.StateConvertException {
		if(this != Freezed){
			throw new com.sh_lianjing.state.StateConvertException(this, Normaled);
		}
		return new com.sh_lianjing.state.StateTransition<State_User>("恢复", this, Normaled);
	}

	/** <b>创建</b> */
	public static com.sh_lianjing.state.StateTransition<State_User> t_create() {
		return new com.sh_lianjing.state.StateTransition<State_User>("创建", null, Normaled);
	}

	/**
	 * to 转换方法相关
	 */

	/**
	 * 验证方法相关
	 */
	public Validator validator(){
		return new Validator();
	}
	
	public class Validator {
		private com.sh_lianjing.state.validate.StateCondition<State_User> condition = new com.sh_lianjing.state.validate.StateCondition<>();
	
		public State_User end() throws com.sh_lianjing.state.StateException{
			if(!condition.validate(State_User.this)){
				throw new com.sh_lianjing.state.StateException("用户状态错误，不能执行操作");
			}
			return State_User.this;
		}
	
		/** <b>验证[已冻结]状态</b> */
		public Validator v_Freezed() {
			this.condition.add(Freezed);
			return this;
		}
		/** <b>验证[正常]状态</b> */
		public Validator v_Normaled() {
			this.condition.add(Normaled);
			return this;
		}
	}

}
